home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / TransSkel.cpt / EventLog.pas < prev    next >
Pascal/Delphi Source File  |  1987-01-11  |  19KB  |  902 lines

  1. {    EventLog - TransDisplay event-logging demonstration program}
  2.  
  3. {    The project should include EventLog.c (this file), TransDisplay.c}
  4. {    (or a project made from TransDisplay.c), TransSkel.c (or a project}
  5. {    made from TransSkel.c), and MacTraps.}
  6.  
  7. {    8 November 1986    Paul DuBois}
  8.  
  9. {11 January 1987    Ported to LightSpeed Pascal by Owen Hartnett    }
  10. {Ωhm Software Co., 163 Richard Drive, Tiverton, RI 02878        }
  11.  
  12. PROGRAM EventLog;
  13.  
  14.     USES
  15.         TransSkelPas, TransDisplay;
  16.  
  17.     CONST
  18.  
  19.                     { declare zoom box part codes }
  20.  
  21.         inZoomIN = 7;
  22.         inZoomOut = 8;
  23.  
  24.         maxButton = 14;
  25.  
  26.         helpTextRes = 1000;        { help text resource number }
  27.         aboutAlrtRes = 1000;    { About... alert resource number }
  28.  
  29.                     { Menu resource numbers }
  30.  
  31.         fileMenuRes = 1000;
  32.         editMenuRes = 1001;
  33.         logMenuRes = 1002;
  34.  
  35.                     { Window resource numbers }
  36.  
  37.         LogWindRes = 1000;
  38.         helpWindRes = 1001;
  39.         SelectWindRes = 1002;
  40.  
  41.             { File menu item numbers }
  42.  
  43.         showLog = 1;    { make windows visible/bring to front }
  44.         showHelp = 2;
  45.         ShowSelect = 3;
  46.         quit = 5;
  47.  
  48.                 { Edit menu item numbers }
  49.  
  50.         undo = 1;
  51.         cut = 3;
  52.         copy = 4;
  53.         paste = 5;
  54.         clear = 6;
  55.  
  56.                 { Log menu item numbers }
  57.  
  58.         logEvents = 1;        { whether events are logged }
  59.         excludeLWind = 2;
  60.         flushLog = 4;                { flush log output }
  61.         wrapStyle = 6;            { word wrap or not }
  62.         leftJust = 8;                { justification }
  63.         centerJust = 9;
  64.         rightJust = 10;
  65.         small = 12;                { text size }
  66.         medium = 13;
  67.         large = 14;
  68.         top = 16;                    { scroll home }
  69.         bottom = 17;                { scroll to bottom }
  70.  
  71.     TYPE
  72.         booleanPtr = ^Boolean;
  73.         CtrlInfoPtr = ^CtrlInfoRec;
  74.         CtrlInfoRec = RECORD
  75.                 loc : Point;        { upper left of control }
  76.                 title : Str255;        { control title }
  77.                 flagAddr : booleanPtr;    { associated boolean }
  78.                 ctrl : ControlHandle;        { associated control }
  79.                 subInfo : CtrlInfoPtr;    { subsidiary control }
  80.             END;
  81.  
  82.  
  83.     VAR
  84.         selectWind, helpWind, logWind : WindowPtr;
  85.             { event selection window }
  86.             { help text window }
  87.             { log output window }
  88.         fileMenu, editMenu, logMenu : MenuHandle;
  89.         reportEvents, excludeLog : Boolean;
  90.         { report events or not }
  91.         { exclude log window events or not }
  92.         logFont, logSize : integer;
  93.         logWrap, logJust : integer;
  94.         rMouseDown, rMouseMods, rMouseWind, rMouseLoc : Boolean;
  95.                             { event type selection flags }
  96.         rMousePart, rMouseSys, rMouseUp, rKeyDown, rKDMods : Boolean;
  97.         rAutoKey, rAKMods, rUpdate, rActivate, rDisk : Boolean;
  98.  
  99. {    Control information.  The last field is used to tell which controls}
  100. {    are "owned" by another.  When the owner is unchecked, all the owned}
  101. {    controls go dim.}
  102.  
  103.         ctrlInfo : ARRAY[0..maxButton] OF CtrlInfoRec;
  104.  
  105. {    Window that was in front last time checked    }
  106.  
  107.         lastFront : WindowPtr;
  108.         h : Handle;
  109.  
  110. {    Do in Pascal what can be done in C as static initializations.  }
  111.  
  112.     PROCEDURE setupStuff;
  113.  
  114.     BEGIN
  115.         rMouseDown := true;
  116.         rMouseMods := false;
  117.         rMouseWind := true;
  118.         rMouseLoc := false;
  119.         rMousePart := true;
  120.         rMouseSys := false;
  121.         rMouseUP := false;
  122.         rKeyDown := true;
  123.         rKDMods := false;
  124.         rAutoKey := true;
  125.         rAKMods := false;
  126.         rUpdate := true;
  127.         rActivate := true;
  128.         rDisk := true;
  129.  
  130.         WITH ctrlInfo[0] DO
  131.             BEGIN
  132.                 loc.v := 5;
  133.                 loc.h := 10;
  134.                 title := 'Mouse Down';
  135.                 flagAddr := @rMouseDown;
  136.                 ctrl := NIL;
  137.                 subInfo := NIL;
  138.             END;
  139.  
  140.         WITH ctrlInfo[1] DO
  141.             BEGIN
  142.                 loc.v := 25;
  143.                 loc.h := 30;
  144.                 title := 'Modifiers';
  145.                 flagAddr := @rMouseMods;
  146.                 ctrl := NIL;
  147.                 subInfo := @ctrlInfo[0];
  148.             END;
  149.  
  150.         WITH ctrlInfo[2] DO
  151.             BEGIN
  152.                 loc.v := 45;
  153.                 loc.h := 30;
  154.                 title := 'Window';
  155.                 flagAddr := @rMouseWind;
  156.                 ctrl := NIL;
  157.                 subInfo := @ctrlInfo[0];
  158.             END;
  159.  
  160.         WITH ctrlInfo[3] DO
  161.             BEGIN
  162.                 loc.v := 65;
  163.                 loc.h := 30;
  164.                 title := 'Location';
  165.                 flagAddr := @rMouseLoc;
  166.                 ctrl := NIL;
  167.                 subInfo := @ctrlInfo[0];
  168.             END;
  169.  
  170.         WITH ctrlInfo[4] DO
  171.             BEGIN
  172.                 loc.v := 85;
  173.                 loc.h := 30;
  174.                 title := 'Part Code';
  175.                 flagAddr := @rMousePart;
  176.                 ctrl := NIL;
  177.                 subInfo := @ctrlInfo[0];
  178.             END;
  179.  
  180.         WITH ctrlInfo[5] DO
  181.             BEGIN
  182.                 loc.v := 105;
  183.                 loc.h := 30;
  184.                 title := 'System Clicks';
  185.                 flagAddr := @rMouseSys;
  186.                 ctrl := NIL;
  187.                 subInfo := @ctrlInfo[0];
  188.             END;
  189.  
  190.         WITH ctrlInfo[6] DO
  191.             BEGIN
  192.                 loc.v := 125;
  193.                 loc.h := 10;
  194.                 title := 'Mouse Up';
  195.                 flagAddr := @rMouseUp;
  196.                 ctrl := NIL;
  197.                 subInfo := NIL;
  198.             END;
  199.  
  200.         WITH ctrlInfo[7] DO
  201.             BEGIN
  202.                 loc.v := 5;
  203.                 loc.h := 160;
  204.                 title := 'Key Down';
  205.                 flagAddr := @rKeyDown;
  206.                 ctrl := NIL;
  207.                 subInfo := NIL;
  208.             END;
  209.  
  210.         WITH ctrlInfo[8] DO
  211.             BEGIN
  212.                 loc.v := 25;
  213.                 loc.h := 180;
  214.                 title := 'Modifiers';
  215.                 flagAddr := @rKDMods;
  216.                 ctrl := NIL;
  217.                 subInfo := @ctrlInfo[7];
  218.             END;
  219.  
  220.         WITH ctrlInfo[9] DO
  221.             BEGIN
  222.                 loc.v := 45;
  223.                 loc.h := 180;
  224.                 title := 'AutoKey';
  225.                 flagAddr := @rAutoKey;
  226.                 ctrl := NIL;
  227.                 subInfo := NIL;
  228.             END;
  229.  
  230.         WITH ctrlInfo[10] DO
  231.             BEGIN
  232.                 loc.v := 65;
  233.                 loc.h := 180;
  234.                 title := 'Modifiers';
  235.                 flagAddr := @rAKMods;
  236.                 ctrl := NIL;
  237.                 subInfo := @ctrlInfo[9];
  238.             END;
  239.  
  240.         WITH ctrlInfo[11] DO
  241.             BEGIN
  242.                 loc.v := 85;
  243.                 loc.h := 160;
  244.                 title := 'Update';
  245.                 flagAddr := @rUpdate;
  246.                 ctrl := NIL;
  247.                 subInfo := NIL;
  248.             END;
  249.  
  250.         WITH ctrlInfo[12] DO
  251.             BEGIN
  252.                 loc.v := 105;
  253.                 loc.h := 160;
  254.                 title := 'Activate';
  255.                 flagAddr := @rActivate;
  256.                 ctrl := NIL;
  257.                 subInfo := NIL;
  258.             END;
  259.  
  260.         WITH ctrlInfo[13] DO
  261.             BEGIN
  262.                 loc.v := 125;
  263.                 loc.h := 160;
  264.                 title := 'Disk';
  265.                 flagAddr := @rDisk;
  266.                 ctrl := NIL;
  267.                 subInfo := NIL;
  268.             END;
  269.  
  270.         lastFront := NIL;
  271.     END;
  272.  
  273. {    Print information about a window.  If it's a window with a title,}
  274. {    print the title.  Print whether it's a}
  275. {    desk accessory window.}
  276.  
  277.     PROCEDURE WindowInfo (theWind : WindowPeek);
  278.  
  279.         VAR
  280.             title : Str255;
  281.  
  282.     BEGIN
  283.         GetWTitle(WindowPtr(theWind), title);
  284.         IF title[0] <> char(0) THEN            { window has title }
  285.             BEGIN
  286.                 DisplayChar(' ');
  287.                 DisplayString(title);
  288.             END;
  289.         IF theWind^.windowKind < 0 THEN
  290.             DisplayString(' (DA)');
  291.     END;
  292.  
  293.     PROCEDURE Modifiers (mods : integer);
  294.  
  295.     BEGIN
  296.         DisplayString(' mods ($');
  297.         DisplayHexInt(mods);
  298.         DisplayChar(')');
  299.     END;
  300.  
  301.     PROCEDURE MouseLoc (thePt : Point;
  302.                                     thePort : GrafPtr);
  303.  
  304.         VAR
  305.             savePort : GrafPtr;
  306.  
  307.     BEGIN
  308.         GetPort(savePort);
  309.         SetPort(thePort);
  310.         GlobalToLocal(thePt);
  311.         SetPort(savePort);
  312.         IF rMouseLoc THEN
  313.             BEGIN
  314.                 DisplaySTring(' loc (');
  315.                 DisplayInt(thePt.h);
  316.                 DisplayString(', ');
  317.                 DisplayInt(thePt.v);
  318.                 DisplayChar(')');
  319.             END;
  320.     END;
  321.  
  322. {    Mouse click.  Get the window that the click occurred in, and the}
  323. {    part of the window.}
  324.  
  325. {    Make sure to get all the part codes!  (incl. zoom box stuff)}
  326.  
  327.     PROCEDURE ReportMouse (theEvent : EventRecord);
  328.  
  329.         VAR
  330.             evtPt : Point;
  331.             evtpart : integer;
  332.             evtport : GrafPtr;
  333.  
  334.     BEGIN
  335.         evtPt := theEvent.where;
  336.         evtPart := FindWindow(evtPt, evtPort);
  337.         IF NOT excludeLog OR (evtPort <> logWind) THEN
  338.             BEGIN
  339.                 DisplayString('Mouse Click');
  340.                 CASE evtPart OF
  341.                     inSysWindow : 
  342.  
  343. {    Click in a desk accessory window.}
  344.  
  345.                         IF rMouseSys THEN
  346.                             BEGIN
  347.                                 IF rMousePart THEN
  348.                                     DisplayString(' in system window:');
  349.                                 IF rMouseWind THEN
  350.                                     WindowInfo(WindowPeek(evtPort));
  351.                                 MouseLoc(evtPt, evtport);
  352.                             END;
  353.                     inDesk : 
  354.  
  355. {    Click in desk top.}
  356.  
  357.                         IF rMousePart THEN
  358.                             DisplayString(' in desktop');
  359.                     inMenuBar : 
  360.  
  361. {    Click in menu bar.}
  362.  
  363.                         IF rMousePart THEN
  364.                             DisplayString(' in menu bar');
  365.                     inGrow : 
  366.  
  367. {    Click in grow box.}
  368.  
  369.                         BEGIN
  370.                             IF rMousePart THEN
  371.                                 DisplayString(' in grow region:');
  372.                             IF rMouseWind THEN
  373.                                 WindowInfo(WindowPeek(evtPort));
  374.                             MouseLoc(evtPt, evtPort);
  375.                         END;
  376.                     inDrag : 
  377.  
  378. {    Click in title bar.}
  379.  
  380.                         BEGIN
  381.                             IF rMousePart THEN
  382.                                 DisplayString(' in drag region:');
  383.                             IF rMouseWind THEN
  384.                                 WindowInfo(WindowPeek(evtPort));
  385.                         END;
  386.                     inGoAway : 
  387.  
  388. {    Click in close box.}
  389.  
  390.                         BEGIN
  391.                             IF rMousePart THEN
  392.                                 DisplayString(' in close box:');
  393.                             IF rMouseWind THEN
  394.                                 WindowInfo(WindowPeek(evtPort));
  395.                         END;
  396.                     inZoomIn : 
  397.  
  398. {    Click in zoom-in box.}
  399.  
  400.                         BEGIN
  401.                             IF rMousePart THEN
  402.                                 DisplayString(' in zoom-in box:');
  403.                             IF rMouseWind THEN
  404.                                 WindowInfo(WindowPeek(evtPort));
  405.                         END;
  406.                     inZoomOut : 
  407.  
  408. {    Click in zoom-out box.}
  409.  
  410.                         BEGIN
  411.                             IF rMousePart THEN
  412.                                 DisplayString(' in zoom-out box:');
  413.                             IF rMouseWind THEN
  414.                                 WindowInfo(WindowPeek(evtPort));
  415.                         END;
  416.                     inContent : 
  417.  
  418. {    Click in content region.}
  419.  
  420. {    (Might also check in in control, and if so, print control information)}
  421.  
  422.                         BEGIN
  423.                             IF rMousePart THEN
  424.                                 DisplayString(' in content region:');
  425.                             IF rMouseWind THEN
  426.                                 WindowInfo(WindowPeek(evtPort));
  427.                             MouseLoc(evtPt, evtPort);
  428.                         END;
  429.                     OTHERWISE
  430.                 END;
  431.                 IF rMouseMods THEN
  432.                     Modifiers(theEvent.modifiers);
  433.                 DisplayLn;
  434.             END;
  435.     END;
  436.  
  437.     PROCEDURE ReportKey (what : integer;
  438.                                     c : char;
  439.                                     mods : integer;
  440.                                     modFlag : Boolean);
  441.     BEGIN
  442.         IF what = keyDown THEN
  443.             DisplayString('Key Down: char "')
  444.         ELSE
  445.             DisplayString('Autokey: char"');
  446.         DisplayChar(c);
  447.         DisplayString('" ');
  448.         IF modFlag THEN
  449.             Modifiers(mods);
  450.         Displayln;
  451.     END;
  452.  
  453.     PROCEDURE ReportActivate (theWind : WindowPtr;
  454.                                     mods : integer);
  455.  
  456.     BEGIN
  457.         IF BitAnd(mods, activeFlag) <> 0 THEN
  458.             DisplayString('Activate:')
  459.         ELSE
  460.             DisplayString('Deactivate:');
  461.         WindowInfo(WindowPeek(theWind));
  462.         DisplayLn;
  463.     END;
  464.  
  465.     PROCEDURE ReportUpdate (theWind : WindowPtr);
  466.  
  467.     BEGIN
  468.         DisplayString('Update:');
  469.         WindowInfo(WindowPeek(theWind));
  470.         Displayln;
  471.     END;
  472.  
  473. {    General event logger}
  474.  
  475.     FUNCTION Logevent (theEvt : EventRecord) : Boolean;
  476.  
  477.         VAR
  478.             theEvent : EventRecord;
  479.             evtPt : Point;
  480.             evtPort : GrafPtr;
  481.             evtpart : integer;
  482.             evtChar : char;
  483.             evtMods : integer;
  484.             r : Rect;
  485.  
  486.     BEGIN
  487.         IF reportEvents = false THEN
  488.             logevent := false
  489.         ELSE
  490.             BEGIN
  491.                 theEvent := theEvt;
  492.                 evtPt := theEvent.where;
  493.                 CASE theEvent.what OF
  494.                     mouseDown : 
  495.  
  496. {    Mouse click.}
  497.  
  498.                         IF rMouseDown THEN
  499.                             ReportMouse(theEvent);
  500.                     mouseUp : 
  501.                         IF rMouseUP THEN
  502.                             BEGIN
  503.                                 DisplayString('Mouse Up');
  504.                                 Displayln;
  505.                             END;
  506.                     keyDown : 
  507.  
  508. {    Key event.}
  509.  
  510.                         IF NOT (excludeLog AND (FrontWindow = logWind)) THEN
  511.                             IF rKeyDown THEN
  512.                                 BEGIN
  513.                                     evtChar := char(BitAnd(theEvent.message, charCodeMask));
  514.                                     evtMods := theEvent.modifiers;
  515.                                     ReportKey(keyDown, evtChar, evtMods, rKDMods);
  516.                                 END;
  517.                     autoKey : 
  518.                         IF NOT (excludeLog AND (FrontWindow = logWind)) THEN
  519.                             IF rKeyDown THEN
  520.                                 BEGIN
  521.                                     evtChar := char(BitAnd(theEvent.message, charCodeMask));
  522.                                     evtMods := theEvent.modifiers;
  523.                                     ReportKey(keyDown, evtChar, evtMods, rKDMods);
  524.                                 END;
  525.                     updateEvt : 
  526.  
  527. {    Update a window.  If it's an update for the log window, invalidate}
  528. {    it, because the message is written and will cause a scroll BEFORE}
  529. {    the window actually gets updated.  This means that part of what}
  530. {    needs redrawing will be scrolled out of the update region and won't}
  531. {    be redrawn properly.  Invalidating the entire port is wasteful but}
  532. {    makes sure the whole window can be drawn properly.}
  533.  
  534.                         BEGIN
  535.                             IF WindowPtr(theEvent.message) = logWind THEN
  536.                                 BEGIN
  537.                                     SetPort(logWind);
  538.                                     InvalRect(logWind^.portRect);
  539.                                 END;
  540.                             IF NOT (excludeLog AND (WindowPtr(theEvent.message) = logWind)) THEN
  541.                                 IF rUpdate THEN
  542.                                     BEGIN
  543.                                         ReportUpdate(WindowPtr(theEvent.message));
  544.                                     END;
  545.                         END;
  546.                     activateEvt : 
  547.  
  548. {    Activate or deactivate a window.}
  549.  
  550.                         IF NOT (excludeLog AND (WindowPtr(theEvent.message) = logWind)) THEN
  551.                             IF rActivate THEN
  552.                                 BEGIN
  553.                                     ReportActivate(WindowPtr(theEvent.message), theEvent.modifiers);
  554.                                 END;
  555.                     diskEvt : 
  556.  
  557. {    handle inserts of uninitialized disks}
  558.  
  559.                         IF rDisk THEN
  560.                             BEGIN
  561.                                 DisplayString('Disk insertion');
  562.                                 IF HiWord(theEvent.message) <> noErr THEN
  563.                                     DisplayString(' (needs initializing)');
  564.                                 Displayln;
  565.                             END;
  566.                 END;
  567.                 logEvent := false;
  568.             END;
  569.     END;
  570.  
  571. {    Background procedure.  Check front window, reset edit menu if window}
  572. {    changes from an application window to a non-application window.}
  573. {    Disable the Edit menu whenever an application window is active,}
  574. {    enable it otherwise.}
  575. {    Also called whenever it is known that the active window has changed.}
  576.  
  577.     PROCEDURE CheckFront;
  578.  
  579.         VAR
  580.             curWind : WindowPtr;
  581.             theKind : integer;
  582.             lastIsApp, curIsApp : Boolean;
  583.             mypeek : WindowPeek;
  584.  
  585.     BEGIN
  586.         curIsApp := false;
  587.         lastIsApp := false;
  588.         curWind := frontwindow;
  589.         IF (IsDWindow(lastFront)) OR (lastFront = selectWind) THEN
  590.             lastIsApp := true;
  591.         IF (IsDWindow(curWind)) OR (curWind = selectWind) THEN
  592.             curIsApp := true;
  593.         IF lastFront <> curWind THEN
  594.             BEGIN
  595.                 IF (IsDWindow(lastFront)) OR (lastFront = selectWind) THEN
  596.                     lastIsApp := true;
  597.                 IF (IsDWindow(curWind)) OR (curWind = selectWind) THEN
  598.                     curIsApp := true;
  599.                 IF lastIsApp <> curIsApp THEN
  600.                     BEGIN
  601.                         theKind := 0;
  602.                         IF curWind <> NIL THEN
  603.                             BEGIN
  604.                                 mypeek := windowpeek(curWind);
  605.                                 theKind := mypeek^.windowKind;
  606.                             END;
  607.                         IF (curWind = NIL) OR (theKind < 0) THEN    { no window or DA in front }
  608.                             EnableItem(editMenu, 0)
  609.                         ELSE
  610.                             DisableItem(editMenu, 0);
  611.                         DrawMenuBar;
  612.                     END;
  613.                 lastFront := curWind;
  614.             END;
  615.     END;
  616.  
  617. { ------------------------------------------------------------ }
  618. {            Event Selection Window Handler Routines                }
  619. { ------------------------------------------------------------ }
  620.  
  621.  
  622.  
  623. {    Activate event procedure for both display windows and the checkbox}
  624. {    window.}
  625.  
  626.     PROCEDURE Activate (active : Boolean);
  627.  
  628.     BEGIN
  629.         CheckFront;
  630.     END;
  631.  
  632. {    Update window.  This is easy, just draw the controls.}
  633.  
  634.     PROCEDURE Update (resized : Boolean);
  635.  
  636.     BEGIN
  637.         DrawControls(selectwind);
  638.     END;
  639.  
  640. {    Handle hits in check boxes:}
  641. {    Toggle check box, sync the associated flag, and enable or disable}
  642. {    any subsidiary check boxes accordingly.  (Subsidiaries have}
  643. {    information in the control structure that points back to the owner}
  644. {    check box.)}
  645.  
  646.     PROCEDURE Mouse (thePt : Point;
  647.                                     t : longint;
  648.                                     mods : integer);
  649.  
  650.         VAR
  651.             ctl : ControlHandle;
  652.             ci : CtrlInfoPtr;
  653.             val : boolean;
  654.             i : integer;
  655.             genericPtr : BooleanPtr;
  656.  
  657.     BEGIN
  658.         IF FindControl(thePt, selectWind, ctl) <> 0 THEN
  659.             IF TrackControl(ctl, thePt, NIL) <> 0 THEN
  660.                 BEGIN
  661.                     ci := CtrlInfoPtr(GetCRefcon(ctl));
  662.                     val := NOT (GetCtlValue(ctl) <> 0);
  663.                     genericPtr := BooleanPtr(ci^.flagAddr);
  664.                     genericPtr^ := val;
  665.                     SetCtlValue(ctl, integer(val));
  666.  
  667.             { enable/disable any subsidiaries }
  668.  
  669.                     FOR i := 0 TO maxButton - 1 DO
  670.                         IF ctrlInfo[i].subInfo^.ctrl = ci^.ctrl THEN
  671.                             IF val THEN
  672.                                 HiliteControl(ctrlInfo[i].ctrl, 0)
  673.                             ELSE
  674.                                 HiliteControl(ctrlInfo[i].ctrl, 255);
  675.                 END
  676.     END;
  677.  
  678. {    File menu handler}
  679.  
  680.     PROCEDURE DoFileMenu (item : integer);
  681.  
  682.     BEGIN
  683.         CASE item OF
  684.             showHelp : 
  685.                 BEGIN
  686.                     SelectWindow(helpWind);
  687.                     ShowWindow(helpWind);
  688.                 END;
  689.             showSelect : 
  690.                 BEGIN
  691.                     SelectWindow(selectWind);
  692.                     ShowWindow(selectWind);
  693.                 END;
  694.             showLog : 
  695.                 BEGIN
  696.                     SelectWindow(logWind);
  697.                     ShowWindow(logWind);
  698.                 END;
  699.             quit : 
  700.                 SkelWhoa;
  701.             OTHERWISE
  702.         END;
  703.     END;
  704.  
  705. {    Put the right check marks in the Log menu}
  706.  
  707.     PROCEDURE SetLogMenu;
  708.  
  709.     BEGIN
  710.         CheckItem(logMenu, logEvents, reportEvents);
  711.         CheckItem(logMenu, excludeLWind, excludeLog);
  712.         CheckItem(logMenu, wrapStyle, logWrap >= 0);
  713.         CheckItem(logMenu, leftJust, logJust = teJustLeft);
  714.         CheckItem(logMenu, centerJust, logjust = teJustCenter);
  715.         CheckItem(logMenu, rightJust, logJust = teJustRight);
  716.         CheckItem(logMenu, small, logsize = 9);
  717.         CheckItem(logMenu, medium, logsize = 12);
  718.         CheckItem(logMenu, large, logSize = 24);
  719.     END;
  720.  
  721. {    Set display style of log window}
  722.  
  723.     PROCEDURE SetStyle;
  724.  
  725.     BEGIN
  726.         SetDWindowStyle(logWind, logFont, logSize, logWrap, logJust);
  727.         SetLogMenu;
  728.     END;
  729.  
  730. {    Log menu handler}
  731.  
  732.     PROCEDURE DoLogMenu (item : integer);
  733.  
  734.     BEGIN
  735.         CASE item OF
  736.             logEvents : 
  737.                 BEGIN
  738.                     reportEvents := NOT reportEvents;
  739.                     SetLogMenu;
  740.                 END;
  741.             excludeLWind : 
  742.                 BEGIN
  743.                     excludeLog := NOT excludeLog;
  744.                     SetLogMenu;
  745.                 END;
  746.             flushLog : 
  747.                 FlushDWindow(logWind, longint(32767));
  748.             wrapStyle : 
  749.                 BEGIN
  750.                     IF logWrap >= 0 THEN
  751.                         logWrap := -1
  752.                     ELSE
  753.                         logWrap := 0;
  754.                     SetStyle;
  755.                 END;
  756.             leftJust : 
  757.                 BEGIN
  758.                     logJust := teJustLeft;
  759.                     SetStyle;
  760.                 END;
  761.             centerJust : 
  762.                 BEGIN
  763.                     logJust := teJustCenter;
  764.                     SetStyle;
  765.                 END;
  766.             rightJust : 
  767.                 BEGIN
  768.                     logJust := teJustRight;
  769.                     SetStyle;
  770.                 END;
  771.             small : 
  772.                 BEGIN
  773.                     logFont := monaco;
  774.                     logSize := 9;
  775.                     SetStyle;
  776.                 END;
  777.             medium : 
  778.                 BEGIN
  779.                     logFont := systemFont;
  780.                     logSize := 12;
  781.                     SetStyle;
  782.                 END;
  783.             large : 
  784.                 BEGIN
  785.                     logFont := geneva;
  786.                     logSize := 24;
  787.                     SetStyle;
  788.                 END;
  789.             top : 
  790.                 SetDWindowPos(logWind, 0);
  791.             bottom : 
  792.                 SetDWindowPos(logWind, 32767);
  793.             OTHERWISE
  794.         END;
  795.     END;
  796.  
  797. {    Handle selection of About… item from Apple menu}
  798.  
  799.     PROCEDURE DoAbout;
  800.  
  801.         VAR
  802.             ignore : integer;
  803.  
  804.     BEGIN
  805.         ignore := Alert(aboutAlrtRes, NIL);
  806.     END;
  807.  
  808. {    Dispose of event selection window (and controls)}
  809.  
  810.     PROCEDURE WClobber;
  811.  
  812.     BEGIN
  813.         DisposeWindow(selectWind);
  814.     END;
  815.  
  816. {    Create controls}
  817.  
  818.     PROCEDURE MakeControls (theWind : windowPtr);
  819.  
  820.         VAR
  821.             i : integer;
  822.             ci : CtrlInfoPtr;
  823.             r : Rect;
  824.             genericPtr : booleanPtr;
  825.  
  826.     BEGIN
  827.         FOR i := 0 TO maxButton - 1 DO
  828.             BEGIN
  829.                 ci := @ctrlInfo[i];
  830.                 SetRect(r, ci^.loc.h, ci^.loc.v, ci^.loc.h + StringWidth(ci^.title) + 30, ci^.loc.v + 20);
  831.                 genericPtr := ci^.flagAddr;
  832.                 ci^.ctrl := NewControl(theWind, r, ci^.title, true, integer(genericPtr^), 0, 1, checkBoxProc, longint(ci));
  833.             END;
  834.         ValidRect(theWind^.portRect);
  835.     END;
  836.  
  837. BEGIN
  838.     SetupStuff;
  839.     SkelInit;
  840.     TransDisplayInit;
  841.     SkelApple('About EventLog...', @DoAbout);
  842.     fileMenu := GetMenu(fileMenuRes);
  843.     SkelMenu(fileMenu, @DoFileMenu, NIL);
  844.  
  845.     editMenu := GetMenu(editMenuRes);
  846.     DisableItem(editmenu, 0);
  847.     SkelMenu(editMenu, NIL, NIL);
  848.  
  849.     logMenu := GetMenu(logMenuRes);
  850.     Skelmenu(logMenu, @DoLogmenu, NIL);
  851.  
  852. {    Create windows and install handlers.}
  853.  
  854.     SetDwindowNotify(NIL, @Activate);
  855.  
  856.     helpWind := GetNEwDWindow(helpWindRes, WindowPtr(-1));
  857.     SetDWindowStyle(helpWind, 0, 0, 0, teJustLeft);
  858.  
  859.     h := GetREsource('TEXT', helpTextRes);    { read help text }
  860.     HLock(h);                            { lock it and write to window }
  861.     DisplayText(h^, GetHandleSize(h));
  862.     HUnlock(h);
  863.     ReleaseResource(h);                { done with it, so goodbye }
  864.     SetDWindowPos(helpWind, 0);        { scroll back to top }
  865.     ShowWindow(helpWind);
  866.  
  867.     logWind := GetNewDWindow(logWindRes, WindowPtr(-1));
  868.  
  869.     SkelEventHook(@logEvent);
  870.     reportEvents := true;
  871.     excludeLog := false;
  872.  
  873.     logFont := monaco;
  874.     logSize := 9;
  875.     logWrap := 0;
  876.     logJust := teJustLeft;
  877.     SetStyle;
  878.     ShowWindow(logWind);
  879.  
  880.     selectWind := GetNewWindow(selectWindRes, NIL, WindowPtr(-1));
  881.  
  882.     SkelWindow(selectWind, @Mouse, NIL, @Update, @Activate, NIL, @WClobber, NIL, true);
  883.         { the window }
  884.         { mouse click handler }
  885.         { key clicks are ignored }
  886.         { window updating procedure }
  887.         { window activate/deactivate procedure }
  888.         { hide window }
  889.         { window disposal procedure }
  890.         { idle proc }
  891.         { irrelevant }
  892.  
  893.     MakeControls(selectWind);
  894.  
  895. {    Process events until user quits,}
  896. {    then clean up and exit}
  897.  
  898.     CheckFront;
  899.     SkelBackground(@CheckFront);
  900.     SkelMain;
  901.     SkelClobber;
  902. END.